//
//  TrademarkDetailController.m
//  PASystem
//
//  Created by 刘沿 on 16/8/17.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "TrademarkDetailController.h"
#import "TrademarkDetailModel.h"

@interface TrademarkDetailController ()

@property (nonatomic,strong) NSMutableArray *dataArray;


@end

@implementation TrademarkDetailController

-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        
        _dataArray = [NSMutableArray array];
    }
    
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self loadData];
}

- (void)loadData{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json = [NSString stringWithFormat:@"{'action': zscqMch,'service': %@, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",_service,userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        NSDictionary *dict = JSON[@"reason"];
        
        NSDictionary *dic = dict[@"attrs"];
        
        TrademarkDetailModel *model = [TrademarkDetailModel mj_objectWithKeyValues:dic];
        
        [self.dataArray addObject:model];
       
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TrademarkDetailModel *model = self.dataArray.firstObject;
    
    if (indexPath.row == 0) {
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10,120, 40)];
        
        label.text = @"申请企业名称:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        
        lbl2.text = model.NAME;
        lbl2.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right);
        }];
        
        
        return cell;
        
    }else if (indexPath.row == 1){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        
        label.text = @"案件类别:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.TYPE;
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right);
        }];
        
        
        return cell;
        
        
    }
    else if (indexPath.row == 2){
        
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 40)];
        
        label.text = @"申请人电话:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.PHON;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right);
        }];
        
        
        return cell;
        
        
    }
    else if (indexPath.row == 3){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10,80, 40)];
        
        label.text = @"申请国家:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.COUNTRY;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right);
        }];
        
        
        return cell;
        
    }
    else if (indexPath.row == 4){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        
        label.text = @"申请时间:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        NSString *string = model.TIME;
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
        fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
        NSDate *date = [fmt dateFromString:string];
        NSDateFormatter *fm = [[NSDateFormatter alloc] init];
        fm.dateFormat = @"yyyy-MM-dd";
        NSString *selfYear = [fm stringFromDate:date];
        
        lbl2.text = selfYear;
        lbl2.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right);
        }];
        
        
        return cell;
    }
    else if (indexPath.row == 5){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 120, 40)];
        
        label.text = @"案件内容概述:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
                 CGFloat titleSize = [OAToolBox sizebyText:model.SUMMARY font:12 minsWidth:120];

      if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}

                lbl2.frame = CGRectMake(label.right, label.top,KScreenWidth  -130, titleSize) ;
        lbl2.font = [UIFont systemFontOfSize:15];
        
        lbl2.text = model.SUMMARY;
        lbl2.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:lbl2];
        
        
        
        return cell;
        
    }
    else if (indexPath.row == 6){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 120,cell.contentView.height)];
        
        label.text = @"案件工作内容:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
         CGFloat titleSize = [OAToolBox sizebyText:model.CONTENT font:12 minsWidth:120];

      if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}

        UILabel *lbl2 = [[UILabel alloc] init];
                lbl2.frame = CGRectMake(label.right, label.top,KScreenWidth  -130, titleSize) ;

        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.CONTENT;
        
        [cell.contentView addSubview:lbl2];

        
        
        return cell;
        
    }else{
    
        return nil;
    }



}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TrademarkDetailModel *model = self.dataArray.firstObject;
if (indexPath.row == 5){
 CGFloat titleSize = [OAToolBox sizebyText:model.SUMMARY font:15 minsWidth:130];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}
if (indexPath.row == 6) {
 CGFloat titleSize = [OAToolBox sizebyText:model.CONTENT font:15 minsWidth:130];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}

else{

return 44;
}


}



@end









